<template>
  <div class="register-page">
    <div class="register-container">
      <div class="register-header">
        <router-link to="/" class="logo-link">
          <img src="../../assets/logo.svg" alt="柯基工具箱" class="logo-image" />
          <h1 class="logo-text">柯基工具箱</h1>
        </router-link>
      </div>
      
      <RegisterForm
        @register-success="handleRegisterSuccess"
        @switch-mode="goToLogin"
      />
      
      <div class="register-footer">
        <p>已有账号？<router-link to="/login" class="login-link">直接登录</router-link></p>
      </div>
    </div>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router';
import { ElMessage } from 'element-plus';
import RegisterForm from '../../components/user/RegisterForm.vue';

const router = useRouter();

// 注册成功处理
const handleRegisterSuccess = () => {
  ElMessage({
    message: '注册成功，请登录',
    type: 'success',
    duration: 3000
  });
  // 跳转到登录页并添加from=register参数，表明是注册成功后跳转过来的
  router.push({
    path: '/login',
    query: { from: 'register' }
  });
};

// 切换到登录页面
const goToLogin = () => {
  router.push('/login');
};
</script>

<style scoped>
.register-page {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  padding: 40px 20px;
}

.register-container {
  width: 100%;
  max-width: 550px;
  animation: fadeIn 0.8s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.register-header {
  text-align: center;
  margin-bottom: 50px;
}

.logo-link {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--black);
  transition: transform 0.3s ease;
}

.logo-link:hover {
  transform: scale(1.05);
}

.logo-image {
  height: 48px;
  margin-right: 16px;
}

.logo-text {
  font-size: 28px;
  font-weight: 700;
  color: var(--black);
  letter-spacing: 0.5px;
}

.register-footer {
  text-align: center;
  margin-top: 40px;
  color: var(--dark-gray);
  font-size: 16px;
}

.login-link {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 600;
  transition: all 0.3s;
  position: relative;
  padding-bottom: 2px;
}

.login-link:after {
  content: '';
  position: absolute;
  width: 0;
  height: 2px;
  bottom: 0;
  left: 0;
  background-color: var(--primary-color);
  transition: width 0.3s ease;
}

.login-link:hover {
  color: var(--primary-dark);
}

.login-link:hover:after {
  width: 100%;
}

@media (max-width: 768px) {
  .register-container {
    max-width: 100%;
  }
  
  .logo-image {
    height: 40px;
  }
  
  .logo-text {
    font-size: 24px;
  }
}

@media (max-width: 480px) {
  .register-page {
    padding: 20px 16px;
  }
  
  .register-header {
    margin-bottom: 30px;
  }
  
  .logo-image {
    height: 36px;
  }
  
  .logo-text {
    font-size: 22px;
  }
}
</style> 